/*
 * @Descripttion: 退出登录  逻辑
 * @version: 
 * @Author: yuanliutech
 * @Date: 2022-11-22 10:08:14
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2023-02-20 14:56:24
 */
const app = getApp()
import {
    showMsg
} from '../../../../utils/config.js'
import {
    reqLogout,
} from '../../../../request/api.js'
module.exports = Behavior({
    data: {},
    methods: {
        async exitLogin() {
            await this.reqLogoutFun()
            await this.clearStorage()
            wx.reLaunch({
                url: '/pages/login/login',
            })
        },
        //   调接口退出登录
        async reqLogoutFun() {
            let params = {
                id: app.globalData.userId
            }
            const res = await reqLogout(params)
            if (res.code !== 20000) return showMsg(res.message)
        },

        // 清空缓存
        clearStorage() {
            wx.clearStorage()
            app.globalData.userId = app.globalData.token = app.globalData.mobile = app.globalData.nickname = app.globalData.tenantId = app.globalData.username = app.globalData.unitLevelList = ''
            app.globalData.openId = app.globalData.wxNickName = ''
            app.globalData.orgId = app.globalData.orgName = ''
            app.globalData.rolename = app.globalData.descriptionRole = ''
            app.globalData.isTeamManager = false
        }
    }
})